一.建立JSON檔案
二.實際操作json檔案
1.讀取檔案
import json
with open("test.json",mode="r") as file:
data=json.load(file) #data會是一個dict
print(data)
print("name: ",data["name"])
print("version: ",data["version"])
2.改寫檔案
import json
with open("test.json",mode="r") as file:
data=json.load(file)
print(data)
data["name"] = "new name"
with open("test.json",mode="w") as file:
json.dump(data,file)